package com.zlsy.thread.concurrentcontainer.predecessor;

import java.util.*;

/**
 * @author zhouliang
 * @date 2020/8/26 20:55
 * 演示 Collections.synchronizedList(new ArrayList<>())的用法
 */
public class SynchronizedDemo {
    public static void main(String[] args) {
        final Map<String, String> synchronizedMap = Collections.synchronizedMap(new HashMap<>());
        synchronizedMap.put("1", "25000");
        synchronizedMap.put("2", "30000");
        final List<String> synchronizedList = Collections.synchronizedList(new ArrayList<>());
        synchronizedList.add("1");
        synchronizedList.add("2");
        for (int i = 0; i < synchronizedList.size(); i++) {
            System.out.println(synchronizedList.get(i));
        }
        final Set<Map.Entry<String, String>> entries = synchronizedMap.entrySet();
        for (Map.Entry<String, String> next : entries) {
            final String key = next.getKey();
            final String value = next.getValue();
            System.out.println(key);
            System.out.println(value);
        }
    }
}
